﻿using Common.Models;
using Common.Utils;
using Microsoft.AspNetCore.Mvc;
using Wallpaper.Models.DTOs.Base;
using Wallpaper.Models.DTOs.Responses;
using Wallpaper.Services.IService;
using Wallpaper.Services.Service;

namespace WallpaperApi.Controllers
{
    [Route("api/downloadrecords")]
    [ApiController]
    public class DownloadRecordsController : BaseController
    {


        readonly IDownloadRecordService _downloadRecordService;
        readonly ILogger<DownloadRecordsController> _logger;

        public DownloadRecordsController(DownloadRecordService downloadRecordService, ILogger<DownloadRecordsController> logger)
        {
            this._downloadRecordService = downloadRecordService;
            this._logger = logger;
        }


        /// <summary>
        /// 用户下载记录(表格)
        /// </summary>
        /// <param name="download"></param>
        /// <returns></returns>
        [HttpGet("admin/analysis")]
        public async Task<ApiResponse<PagedResult<DownloadRecordResponse>>> CreateDownload([FromBody] TimeRangeQuery query)
        {
            PagedResult<DownloadRecordResponse> result = await _downloadRecordService.UsersDownloadHistory(query);
            return ApiResponse<PagedResult<DownloadRecordResponse>>.Success(result);
        }


    
        /// <summary>
        /// 获取个人下载记录
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpGet("user-history")]
        public async Task<ApiResponse<PagedResult<DownloadRecordUserResponse>>> DownloadHistory([FromQuery] QueryRequest query)
        {
            PagedResult<DownloadRecordUserResponse> result = await _downloadRecordService.DownloadHistory(query,UserId);
            return ApiResponse<PagedResult<DownloadRecordUserResponse>>.Success(result);
        }



        /// <summary>
        /// 根据id删除下载记录
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>

        [HttpDelete("{id}")]
        public async Task<ApiResponse<Object>> Delete(string id)
        {
            bool result = await _downloadRecordService.DeleteAsync(id);
            return ApiResponse<Object>.Success();
        }
    }
}
